/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.base.manager.impl;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import com.xy.biz.base.domain.po.QrCodePO;
import com.xy.lang.domain.Result;
import com.xy.tool.constant.QrCodeUrlConstant;
import com.xy.tool.context.UserContextHolder;
import com.xy.tool.util.QRCodeGenerateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xy.biz.base.domain.bo.QrCodeBO;
import com.xy.biz.base.domain.query.QrCodeQuery;
import com.xy.biz.base.domain.converter.QrCodeConverter;
import com.xy.biz.base.manager.QrCodeManager;
import com.xy.biz.base.dao.QrCodeDao;

/**
 *
 *
 * @author zgy
 * @date 2021-8-11
 */
@Slf4j
@Service
public class QrCodeManagerImpl implements QrCodeManager {

    @Autowired
    private QrCodeDao qrCodeDao;

    @Override
    public QrCodeBO saveQrCode(QrCodeBO qrCodeBO) {
        QrCodePO qrCodePO = QrCodeConverter.toPO(qrCodeBO);
        int row = qrCodeDao.saveQrCode(qrCodePO);
        if (row > 0) {
            return QrCodeConverter.fromPO(qrCodePO);
        }
        return null;
    }

    @Override
    public int deleteQrCode(Long qrCodeId) {
        return qrCodeDao.deleteQrCode(qrCodeId);
    }

    /**
     * 判断是否存在相同分类下的文本
     *
     * @param qrCodeBO
     */
    @Override
    public int isExist(QrCodeBO qrCodeBO) {
        return qrCodeDao.isExist(qrCodeBO);
    }

    @Override
    public QrCodeBO getQrCode(Long qrCodeId) {
        return QrCodeConverter.fromPO(qrCodeDao.getQrCode(qrCodeId));
    }

    /**
     * 查找一个
     *
     * @param qrCodeBO
     * @return
     */
    @Override
    public QrCodeBO getQrCodeByText(QrCodeBO qrCodeBO) {
        return QrCodeConverter.fromPO(qrCodeDao.getQrCodeByText(QrCodeConverter.toPO(qrCodeBO)));
    }

    @Override
    public List<QrCodeBO> listQrCodeById(Collection<Long> collection) {
        return QrCodeConverter.fromPO(qrCodeDao.listQrCodeById(collection));
    }

    @Override
    public List<QrCodeBO> listQrCode(QrCodeQuery query) {
        return QrCodeConverter.fromPO(qrCodeDao.listQrCode(query));
    }

    @Override
    public int countQrCode(QrCodeQuery query) {
        return qrCodeDao.countQrCode(query);
    }

}
